package com.kaili.basic.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.kaili.basic.mapper.BaseCheckStoreMapper;
import com.kaili.basic.mapper.BaseStoreAccountsMapper;
import com.kaili.basic.pojo.dto.*;
import com.kaili.basic.pojo.entity.*;
import com.kaili.basic.pojo.vo.*;
import com.kaili.basic.service.*;
import com.kaili.common.response.CommonStatus;
import com.kaili.common.response.RestStatus;
import com.kaili.common.util.LoginDetailUtils;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Service
@Transactional
public class BaseStoreAccountsServiceImpl extends ServiceImpl<BaseStoreAccountsMapper, BaseStoreAccountsEntity> implements BaseStoreAccountsService {


    @Override
    public void insertBath(List<?> list) {
        List<BaseStoreAccountsEntity> accountsList=new ArrayList<>();
        //入库管理
        for (Object obj:list)
            if (obj instanceof BaseInStoreDetailEntity) {
                BaseStoreAccountsEntity entity=new BaseStoreAccountsEntity();
                BaseInStoreDetailEntity detail = (BaseInStoreDetailEntity) obj;
                BeanUtils.copyProperties(detail,entity);
                entity.setAccountsType("入库");
                entity.setDestLocationId(detail.getLocationId());
                entity.setDestStoreId(detail.getStoreId());
                entity.setCreateBy(LoginDetailUtils.getCurrentEmployeeId().longValue());
                entity.setCreateTime(new Date());
                accountsList.add(entity);
                //移库管理
            } else if (obj instanceof BaseMoveStoreDetailEntity) {
                BaseStoreAccountsEntity entity=new BaseStoreAccountsEntity();
                BaseMoveStoreDetailEntity detail = (BaseMoveStoreDetailEntity) obj;
                BeanUtils.copyProperties(detail,entity);
                entity.setAccountsType("移库-出");
                entity.setSrcLocationId(detail.getSrcLocationId());
                entity.setSrcStoreId(detail.getStoreId());
                entity.setDestLocationId(detail.getDestLocationId());
                entity.setDestStoreId(detail.getStoreId());
                entity.setCreateBy(LoginDetailUtils.getCurrentEmployeeId().longValue());
                entity.setCreateTime(new Date());
                accountsList.add(entity);
                BaseStoreAccountsEntity entity2=new BaseStoreAccountsEntity();
                BeanUtils.copyProperties(entity,entity2);
                entity2.setAccountsType("移库-入");
                accountsList.add(entity2);
                //报损管理
            } else if (obj instanceof BaseReportLossDetailEntity) {
                BaseStoreAccountsEntity entity=new BaseStoreAccountsEntity();
                BaseReportLossDetailEntity detail = (BaseReportLossDetailEntity) obj;
                BeanUtils.copyProperties(detail,entity);
                entity.setAccountsType("报损-出");
                entity.setSrcLocationId(detail.getSrcLocationId());
                entity.setSrcStoreId(detail.getStoreId());
                entity.setDestLocationId(detail.getLossLocationId());
                entity.setDestStoreId(detail.getStoreId());
                entity.setCreateBy(LoginDetailUtils.getCurrentEmployeeId().longValue());
                entity.setCreateTime(new Date());
                accountsList.add(entity);
                BaseStoreAccountsEntity entity2=new BaseStoreAccountsEntity();
                BeanUtils.copyProperties(entity,entity2);
                entity2.setAccountsType("报损-入");
                accountsList.add(entity2);
                //调拨管理
            } else if (obj instanceof BaseAllottedStoreDetailEntity) {
                BaseStoreAccountsEntity entity=new BaseStoreAccountsEntity();
                BaseAllottedStoreDetailEntity detail = (BaseAllottedStoreDetailEntity) obj;
                BeanUtils.copyProperties(detail,entity);
                entity.setAccountsType("调拨-出");
                entity.setSrcLocationId(detail.getSrcLocationId());
                entity.setSrcStoreId(detail.getSrcStoreId());
                entity.setDestLocationId(detail.getDestLocationId());
                entity.setDestStoreId(detail.getDestStoreId());
                entity.setCreateBy(LoginDetailUtils.getCurrentEmployeeId().longValue());
                entity.setCreateTime(new Date());
                accountsList.add(entity);
                BaseStoreAccountsEntity entity2=new BaseStoreAccountsEntity();
                BeanUtils.copyProperties(entity,entity2);
                entity2.setAccountsType("调拨-入");
                accountsList.add(entity2);
            } else if(obj instanceof BaseOutStoreDetailEntity) {
                BaseStoreAccountsEntity entity=new BaseStoreAccountsEntity();
                BaseOutStoreDetailEntity detail = (BaseOutStoreDetailEntity) obj;
                BeanUtils.copyProperties(detail,entity);
                entity.setAccountsType("出库");
                entity.setSrcLocationId(detail.getLocationId());
                entity.setSrcStoreId(detail.getStoreId());
                entity.setCreateBy(LoginDetailUtils.getCurrentEmployeeId().longValue());
                entity.setCreateTime(new Date());
                accountsList.add(entity);
            }

        this.insertBatch(accountsList);
    }


}
